/**
 * Created by billy on 2020/12/21.
 */
var _operationHash = {
	"(": ">",
	")": "<",
	"[": ">=",
	"]": "<=",
}

var _operationFuncHash = {
	">": op_more,
	"<": op_less,
	">=": op_more_equal,
	"<=": op_less_equal,
}

exports.between = function ($value)
{
	$value = $value + "";
	var spllitIndex = $value.indexOf(",");
	if (spllitIndex <= 0)
	{
		return "";
	}
	var minSign = _operationHash[$value.charAt(0)];
	var maxSign = _operationHash[$value.charAt($value.length - 1)];
	if (!minSign || !maxSign)
	{
		return "";
	}
	var result = [];
	var min = $value.substring(1, $value.indexOf(","));
	if (min)
	{
		result.push({
			val: isNum(min) ? Number(min) : min,
			operation: minSign
		});
	}
	var max = $value.substring($value.indexOf(",") + 1, $value.length - 1);
	if (max)
	{
		result.push({
			val: isNum(max) ? Number(max) : max,
			operation: maxSign
		});
	}
	return result;
}

exports.compare = function ($val, $op, $target)
{
	return _operationFuncHash[$op]($val, $target);
}

function op_more(a, b)
{
	return a > b;
}

function op_more_equal(a, b)
{
	return a >= b;
}

function op_less(a, b)
{
	return a < b;
}

function op_less_equal(a, b)
{
	return a <= b;
}